import { Injectable } from '@angular/core';
import {adSystemApiUrl} from '../../../config/api';
import {HttpService} from './http.service';

@Injectable()
export class AddressService {

  constructor(private httpService: HttpService) { }

  // 省列表
  getProvinceList(){
    const url = adSystemApiUrl + '/v1/member/comm/address/province_list';
    return this.httpService.httpGetAuth(url).map(data => data);
  }

  // 市列表
  getCityList(province_id: number){
    const url = adSystemApiUrl + '/v1/member/comm/address/city_list?province_id='+province_id;
    return this.httpService.httpGetAuth(url).map(data => data);
  }

  // 区列表
  getRegionList(city_id: number){
    const url = adSystemApiUrl + '/v1/member/comm/address/region_list?city_id='+city_id;
    return this.httpService.httpGetAuth(url).map(data => data);
  }

  // 联级省市区
  getAddress(){
    const url = adSystemApiUrl + '/v1/member/comm/address/get_address';
    return this.httpService.httpGetAuth(url).map(data => data);
  }

  // 根据区code获取地址信息
  getAddressDetail(code: number){
    const url = `${adSystemApiUrl}/v1/member/comm/address/address_detail?code=${code}`;
    return this.httpService.httpGetAuth(url).map(data => data);
  }
}
